﻿@model DefeatEpidemic.Models.Community
<link href="~/lib/layui-extend/city-picker/citypicker.css" rel="stylesheet" />
<script src="~/lib/layui-extend/city-picker/citypicker.data.js"></script>
<div class="layui-row">
    <span class="layui-breadcrumb">
        <a href="~/home/index">首页</a>
        <a href="~/communities/Index">社区管理</a>
        <a>
            <cite>添加社区</cite>
        </a>
    </span>
    <a class="layui-btn layui-btn-xs" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-1" style="line-height:25px;font-size: 10px"></i>
    </a>
</div>
<hr />

<div class="layui-row">
    <form asp-action="Create" class="layui-form">
        <div asp-validation-summary="ModelOnly" class="text-danger"></div>
        <div class="layui-form-item">
            <label asp-for="name" class="layui-form-label"></label>
            <div class="layui-input-block">
                <input asp-for="name" class="layui-input" placeholder="请输入社区姓名" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width_auto text-r" style="margin-top:2px">省市区(县)：</label>
            <div class="layui-input-inline" style="width:400px">
                <input type="text" autocomplete="on" class="layui-input" id="city-picker" name="city-picker" readonly="readonly" data-toggle="city-picker" placeholder="请选择">
            </div>
        </div>
        <div class="layui-form-item">
            <label asp-for="detail" class="layui-form-label"></label>
            <div class="layui-input-block">
                <input asp-for="detail" class="layui-input" placeholder="请输入具体地址" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item" style="padding-left:30px">
            <a class="layui-btn" href="javascript:;" lay-submit lay-filter="save">创建</a>
            <a asp-action="Index" class="layui-btn layui-btn-primary">返回列表</a>
        </div>
    </form>
</div>
<script>
    var token = $('@Html.AntiForgeryToken()').val();
    layui.config({
        base: '/lib/layui-extend/city-picker/'
    }).use(['jquery', 'table','form', 'citypicker'], function () {
        var $ = layui.$
            , table = layui.table
            , form = layui.form
            , cityPicker = layui.citypicker;

        var currentPicker = new cityPicker("#city-picker", {
            provincename: "provinceId",
            cityname: "cityId",
            districtname: "districtId",
            level: 'districtId',// 级别
        });
        currentPicker.setValue("河北省/保定市/莲池区");
        console.log(currentPicker.getVal());
        console.log(currentPicker);
        form.on('submit(save)', function (data) {
            var pca = currentPicker.getVal().split('/');
            var province = pca[0];
            var city = pca[1];
            var area = pca[2];
            var jsonData = {
                "name": data.field.name,
                "province": province,
                "city": city,
                "area": area,
                "detail": data.field.detail,
                "__RequestVerificationToken": token
            };
            var params = {
                'url': '@Url.Action("Create")',
                'type': 'post',
                'data': jsonData,
                'showMsg': true,
                //'refresh': true,
                'jumpurl': '@Url.Action("Index")'
            };
            sendAjax(params);
        });
    })
</script>
